<?php
/**
 * Created by PhpStorm.
 * User: zsm
 * Date: 2018/5/14
 * Time: 11:57
 */
namespace Library\db;
class PdoDriver extends Db implements Singleton{
    protected static $instance=null;

    protected $link;

    public static function getInstance()
    {
       if (is_null(self::$instance)){
           self::$instance=new self();
       }
       return self::$instance;
    }
    protected function __construct()
    {
        $current_conf=Config('db');
        $user = $current_conf['DBUSER'];
        $passwd = $current_conf['DBPWD'];
        $host = $current_conf['DBHOST'];
        $db   = $current_conf['DBNAME'];

        $this->link = mysqli_connect($host,$user,$passwd);

        //mysqli_set_charset($current_conf['DBCHARSET'] , $this->link);
        mysqli_select_db($this->link,$db);

    }
    public function clean($string)
    {
        return mysqli_real_escape_string($this->link,$string);
    }
    public function execute($query)
    {
       return mysqli_query($this->link,$query);

    }

    public function insert_get_id($query){
        $this->execute($query);
        return mysqli_insert_id($this->link);
    }

    public function get_array($query){
        $result = $this->execute($query);
        $return = array();
        if($result){
            while($row = mysqli_fetch_array($result , 1)){
                $return[] =$row;
            }
        }
        return $return;
    }

}